package com.lb.activity.mapper;

import com.lb.activity.po.UserRole;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import tk.mybatis.mapper.common.Mapper;

import java.util.List;

/**
 * 用户角色中间表 mapper
 * @author liubin
 */
public interface UserRoleMapper extends Mapper<UserRole> {


    /**
     * 删除
     * @param userId
     */
    @Delete(" delete from user_role \n" +
            "    where userid = #{userId,jdbcType=DECIMAL}")
    void removeRoleByUserId(Long userId);


    /**
     * 批量添加
     * @param userRoles
     */
    @Insert({"<script> INSERT INTO user_role (id,userid,roleid,status) " +
            "values " +
            "<foreach collection=\"list\" item=\"item\" index=\"index\"  separator=\",\"> "+
            "      (#{item.id,jdbcType=BIGINT},#{item.userid,jdbcType=BIGINT},#{item.roleid,jdbcType=BIGINT},#{item.status,jdbcType=BIGINT})\n" +
            "</foreach> </script>"})
    void batchSave(List<UserRole> userRoles);
}
